//
//  DWERectAnnotationView.m
//  休闲吧
//
//  Created by DWE_KJ on 2017/1/4.
//  Copyright © 2017年 loveMe. All rights reserved.
//

#import "DWERectAnnotationView.h"
#import "Masonry.h"
#import "DWESexView.h"

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

@interface DWERectAnnotationView()
{
    UIView              *_contentView;
    UIImageView         *_bgImageView;
    UIImageView         *_headerImageView;
    DWESexView          *_sexView;
}

@end

@implementation DWERectAnnotationView

- (instancetype)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier])
    {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews
{
    //自定义大头针添加的自定义点击事件必须重新设置系统自带大头针的frame,否则自定义的点击事件不响应
    CGFloat wide = isPad ? 70 : 50;
    self.frame = CGRectMake(0, 0, wide, wide);
    
    _contentView = [[UIView alloc]init];
    _contentView.backgroundColor = [UIColor clearColor];
    
    _bgImageView = [[UIImageView alloc]init];
    _bgImageView.image = [UIImage imageNamed:@"map_porbg"];
    [_contentView addSubview:_bgImageView];
    
    _headerImageView = [[UIImageView alloc]init];
    _headerImageView.center = CGPointMake(_contentView.frame.size.width/2, _contentView.frame.size.height/2);
    CGFloat cornerRadius = isPad ? 30 : 20;
    _headerImageView.layer.cornerRadius = cornerRadius;
    _headerImageView.layer.masksToBounds = YES;
    _headerImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHeaderImageView)];
    [_headerImageView addGestureRecognizer:tap];
    [_contentView addSubview:_headerImageView];
    
    _sexView = [DWESexView new];
    _sexView.backgroundColor = [UIColor clearColor];
    [_headerImageView addSubview:_sexView];
    
    [self addSubview:_contentView];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat width = isPad ? 70 : 50;
        make.left.and.top.mas_equalTo(0);
        make.width.and.height.mas_equalTo(width);
    }];
    
    [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(0);
        CGFloat width = isPad ? 75 : 50;
        CGFloat height = isPad ? 95 : 65;
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat width = isPad ? 60 : 40;
        CGFloat top = isPad ? 7 : 5;
        CGFloat left = isPad ? 7 : 5;
        make.left.mas_equalTo(left);
        make.top.mas_equalTo(top);
        make.width.and.height.mas_equalTo(width);
    }];
    
    [_sexView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.bottom.mas_equalTo(0);
        CGFloat width = isPad ? 60 : 40;
        make.width.and.height.mas_equalTo(width);
    }];
}

- (void)setHeaderImage:(UIImage *)headerImage
{
    _headerImageView.image = headerImage;
}

- (void)setSex:(int)sex
{
    [_sexView showSex:sex];
}

- (void)tapHeaderImageView
{
    if (_clickImageViewBlock) _clickImageViewBlock();
}

@end

#pragma mark -- 附近休闲咖

@interface DWEXXKAnnotationView()
{
    UIView              *_contentView;
    UIImageView         *_bgImageView;
    UIImageView         *_headerImageView;
    UILabel             *_numberLabel;
}
@end

@implementation DWEXXKAnnotationView

- (instancetype)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier])
    {
        [self initWithSubView];
    }
    return self;
}

- (void)initWithSubView
{
    //自定义大头针添加的自定义点击事件必须重新设置系统自带大头针的frame,否则自定义的点击事件不响应
    CGFloat wide = isPad ? 70 : 50;
    self.frame = CGRectMake(0, 0, wide, wide);
    
    _contentView = [[UIView alloc]init];
    _contentView.backgroundColor = [UIColor clearColor];
    
    _bgImageView = [[UIImageView alloc]init];
    _bgImageView.image = [UIImage imageNamed:@"map_porbg"];
    [_contentView addSubview:_bgImageView];
    
    _headerImageView = [[UIImageView alloc]init];
    _headerImageView.center = CGPointMake(_contentView.frame.size.width/2, _contentView.frame.size.height/2);
    CGFloat cornerRadius = isPad ? 30 : 20;
    _headerImageView.layer.cornerRadius = cornerRadius;
    _headerImageView.layer.masksToBounds = YES;
    _headerImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapNameImage)];
    [_headerImageView addGestureRecognizer:tap];
    _headerImageView.backgroundColor = [UIColor yellowColor];
    [_contentView addSubview:_headerImageView];
    
    _numberLabel = [UILabel new];
    _numberLabel.textColor = [UIColor whiteColor];
    _numberLabel.textAlignment = NSTextAlignmentCenter;
    _numberLabel.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
    _numberLabel.font = [UIFont systemFontOfSize:9];
    [_headerImageView addSubview:_numberLabel];
    
    [self addSubview:_contentView];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(0);
        CGFloat width = isPad ? 70 : 50;
        make.width.and.height.mas_equalTo(width);
    }];
    
    [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(0);
        CGFloat width = isPad ? 75 : 50;
        CGFloat height = isPad ? 95 : 65;
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(height);
    }];
    
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat width = isPad ? 60 : 40;
        CGFloat top = isPad ? 7 : 5;
        CGFloat left = isPad ? 7 : 5;
        make.left.mas_equalTo(left);
        make.top.mas_equalTo(top);
        make.width.and.height.mas_equalTo(width);
    }];
    
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat width = isPad ? 60 : 40;
        make.left.and.bottom.mas_equalTo(0);
        make.width.mas_equalTo(width);
    }];
}

- (void)setNameImage:(UIImage *)nameImage
{
    _headerImageView.image = nameImage;
}

- (void)setJsCount:(int)jsCount
{
    _numberLabel.text = [NSString stringWithFormat:@"%d技师",jsCount];
}

- (void)tapNameImage
{
    if (_clickImageBlock) _clickImageBlock();
}

@end
